package com.log;

import java.util.HashMap;
import java.util.Map;

import org.apache.log4j.Logger;


/**
 * 日志
 * 类/接口注释
 * 
 * @author emmerich@126.com
 * @createDate 2014年8月4日
 *
 */
public class Log {
    
    private static Map<String, Logger> LoggerMap = new HashMap<String, Logger>();
    
    private static Logger eframeInfo = Logger.getLogger("eframeINFO");
    
    private static Logger eframeError = Logger.getLogger("eframeERROR");

    /**
     * 自定义节点
     * @param key
     * @return
     */
    private static Logger getLogger(String key){
        Logger log = LoggerMap.get(key);
        
        if(log!=null){
            return log;
        }else{
            log=Logger.getLogger(key);
            LoggerMap.put(key, log);
            return log;
        }
    }
    
    public static void custom(String loggerName, String msg){
        getLogger(loggerName).info(msg);
    }
    
    public static void custom(String loggerName, String msg, Object ... args){
        custom(loggerName, String.format(msg, args));
    }
    
    public static void info(String msg){
        eframeInfo.error(msg);
    }
    
    public static void info(String msg, Object ... args){
        info(String.format(msg, args));
    }    
    
    public static void error(String msg){
        eframeError.error(msg);
    }
    
    public static void error(Throwable t, String msg, Object ... args){
        eframeError.error(String.format(msg, args), t);
    }
    
    public static void error(String msg, Object ... args){
        error(String.format(msg, args));
    }
}
